##!/bin/bash
#
##加入java的环境变量
#export JAVA_HOME=/opt/jdk1.8.0_141
#export PATH=$PATH:$JAVA_HOME/bin
#
##杀死tomcat
#kill $(ps aux | grep tomcat | grep -v grep | awk '{print $2}')
#
##等待java进程结束
#while [ -n "$(ps aux | grep tomcat | grep -v grep)" ];do
#  sleep 5
#done
##删除旧的war包，cp新的war包
#rm -rf /opt/tomcat8/webapps/ROOT*
#cp /tmp/virstu.war /opt/tomcat8/webapps/ROOT.war
##启动tomcat
#/opt/tomcat8/bin/startup.sh
##定义变量i=0；i<5,i+1
#i=0
#while [ $i -lt 5 ]; do
# curl localhost/a.html | grep $BUILD_NUMBER
#if [ $? -eq 0 ]; then
# exit 0
#else
#sleep 5
#fi
#i= $(echo $i+1 | bc)
#done
#exit 1


export JAVA_HOME=/opt/jdk1.8.0_141/
export PATH=$PATH:$JAVA_HOME/bin

kill $( ps aux | grep tomcat8 | grep -v grep | awk '{print $2}'
)
for ((i=0;i<50;i++ )); do
  used=$(netstat -anp | grep 80 -w | grep -v grep)
  if [ -z "$used" ]; then
     # 删掉旧的war包，拷贝新的war包
     rm /opt/tomcat8/webapps/ROOT* -rf
     cp /tmp/virstu.war /opt/tomcat8/webapps/ROOT.war
     #启动
     /opt/tomcat8/bin/startup.sh
     break
  fi
  sleep 5
done

